package com.example.administrator.yuejian2.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Toast;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.abstractclass.BaseActivity;
import com.example.administrator.yuejian2.bean.Register;
import com.example.administrator.yuejian2.model.LoginModel;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class ToRegisterActivity extends BaseActivity {
    private AutoCompleteTextView phoneNumber,edt_uname,edt_pwd;
    private Button btn_confirm;
    @Override
    public void setContentView() {
        setContentView(R.layout.activity_to_register);
    }

    @Override
    public void initView() {
        phoneNumber = (AutoCompleteTextView)findViewById(R.id.phoneNumber);
        edt_uname = (AutoCompleteTextView)findViewById(R.id.edt_uname);
        edt_pwd = (AutoCompleteTextView)findViewById(R.id.edt_pwd);
        btn_confirm = (Button)findViewById(R.id.btn_confirm);
    }

    @Override
    public void initEvent() {
        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Showlist();
            }
        });
    }

    @Override
    public void setTitle() {

    }

    void Showlist(){
        String phone=phoneNumber.getText().toString();
        String name=edt_uname.getText().toString();
        String pwd=edt_pwd.getText().toString();
        LoginModel orderModel = new LoginModel();
        Call call = orderModel.userReg(phone,name,pwd);
        call.enqueue(new Callback<Register>() {
            @Override
            public void onResponse(Call<Register> call, Response<Register> response) {
                if (response.isSuccessful()){
                    Register loginBean = response.body();
                    System.out.println("888888->"+loginBean.getSuccess());
                    if (loginBean.getSuccess()!=0){
//                        Intent intent = new Intent(ToRegisterActivity.this,MainActivity.class);
//                        startActivity(intent);
//                        finish();
                        Toast.makeText(ToRegisterActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
                    }
                    else {
                        Toast.makeText(ToRegisterActivity.this,"注册失败",Toast.LENGTH_SHORT).show();
                    }
                }
            }

            @Override
            public void onFailure(Call<Register> call, Throwable t) {
                //Toast.makeText(ActivityLogin.this,"访问服务器超时",Toast.LENGTH_SHORT).show();
            }
        });
    }
}
